package com.concerneyes.glasses.adapter;


import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.concerneyes.R;

import java.util.List;

import common.AbsBaseView;

/**
 * Created by Kevin on 16/5/1.
 */
public class ViewPagerAdapter extends PagerAdapter {

    private List<AbsBaseView> baseViews = null;
    private Context context;

    public ViewPagerAdapter(Context context, List<AbsBaseView> absBaseViews) {
        this.context = context;
        this.baseViews = absBaseViews;
    }
    public AbsBaseView getView(int position) {
        return baseViews.get(position);
    }
    @Override
    public int getCount() {
        return baseViews == null ? 0 : baseViews.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
    @Override
    public AbsBaseView instantiateItem(ViewGroup container, int position) {
        container.addView(baseViews.get(position));
        return baseViews.get(position);
    }
    @Override
    public int getItemPosition(Object object) {
        return super.getItemPosition(object);
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(baseViews.get(position));
    }
    @Override
    public CharSequence getPageTitle(int position) {
        CharSequence[] textArray = context.getResources().getTextArray(R.array.glass);
        return textArray[position];
    }
}